// space-buccaneer
//
// introstate.cpp


// includes
#include <SFML/Graphics.hpp>
#include "gamestate.h"
#include "engine.h"
#include "introstate.h"
#include "playstate.h"

CIntroState CIntroState::m_IntroState;

void CIntroState::Init()
{

    /* load background and make sprite */
    m_ImageBg.loadFromFile ("images/background_intro.png");
    m_SpriteBg.setTexture (m_ImageBg);
    m_SpriteBg.setPosition (0, 0);
}

void CIntroState::Cleanup()
{

}

void CIntroState::Pause()
{
}

void CIntroState::Resume()
{

}

void CIntroState::HandleEvents(CGameEngine* game)
{
    // Process events
    sf::Event Event;
    while (game->App->pollEvent(Event))
    {
        // Close window : exit
        if (Event.type == sf::Event::Closed)
            game->Quit();

        // A key has been pressed
        if (Event.type == sf::Event::KeyPressed || Event.type == sf::Event::MouseButtonPressed)
        {
            //FadeOut(game);
            /* load the playstate */
            game->ChangeState(CPlayState::Instance());
           // game->ChangeState(CMenuState::Instance());
        }
    }
}

void CIntroState::Update(CGameEngine* game)
{

}

void CIntroState::Draw(CGameEngine* game)
{
    game->App->clear (sf::Color (0, 0, 0));

    game->App->draw (m_SpriteBg);

    game->App->display ();
}

void CIntroState::FadeOut (CGameEngine* game)
{
    for (int i = 0; i < 255; i++)
    {
        m_SpriteBg.setColor (sf::Color (255, 255, 255, 255-i));

        Draw (game);
    }
}
